#include "GUIOverlay.h"
#include "ResourceManagers.h"
#include "Nest.h"


GUIOverlay::GUIOverlay(void)
{
	m_hatchText.SetFont(*FontManager::Instance()->GetFont("arial.ttf"));
	m_heatText.SetFont(*FontManager::Instance()->GetFont("arial.ttf"));
	m_switchText.SetFont(*FontManager::Instance()->GetFont("arial.ttf"));
	m_hatchPlayerText.SetFont(*FontManager::Instance()->GetFont("arial.ttf"));
	m_changeSprite= new AniSprite(*ImageManager::Instance()->GetImage("cartel_cambio.png"),512,165);
	m_changeSprite->SetLoopSpeed(2);
	m_changeSprite->SetPosition(400,250);


	m_hatchText.SetPosition(350,150);
	m_switchText.SetPosition(350,0);
	m_hatchPlayerText.SetPosition(500,0);

    temp_bar=new ProgBar(ImageManager::Instance()->GetImage("temp_bar.png"), ImageManager::Instance()->GetImage("marco_temp_bar.png"));
	m_heatText.SetText("Calor");
	m_heatText.SetPosition(100,15);
	wichMustHatch=0;
}


GUIOverlay::~GUIOverlay(void)
{
}

void GUIOverlay::Update(float dt){
	temp_bar->Update(dt);
	if(timeToShowChange>0){
		timeToShowChange-=dt;
		m_changeSprite->Update();
	}
}

void GUIOverlay::ShowChangeText(float time){

	timeToShowChange=time;
	m_changeSprite->Play(0,2);


}

void GUIOverlay::Draw(RenderWindow* wnd){
		wnd->Draw(m_hatchText);
		//wnd->Draw(m_heatText);
		wnd->Draw(m_switchText);
		wnd->Draw(m_hatchPlayerText);
		temp_bar->Draw(wnd);

		if(timeToShowChange>0)
			wnd->Draw(*m_changeSprite);

        if(wichMustHatch!=0){
            sf::Sprite s;
            sf::Image *i;
            if(wichMustHatch==1){
                i=ImageManager::Instance()->GetImage("hatch_p1.png");
            }else{
                i=ImageManager::Instance()->GetImage("hatch_p2.png");
            }
            s.SetImage(*i);
            s.SetPosition(Nest::Instance()->GetPosition());
            s.SetCenter(i->GetWidth()/2, i->GetHeight()/2);
            s.Move(0, -75);
            wnd->Draw(s);
        }

}

GUIOverlay* GUIOverlay::Instance(){

		static GUIOverlay instance;
		return &instance;
}

void GUIOverlay::SetHatchKeys(std::string text){
	m_hatchText.SetText(text);
}

void GUIOverlay::SetHeat(std::string text){
	m_heatText.SetText(text);
}

void GUIOverlay::SetTimeToSwitch(std::string text){
	m_switchText.SetText(text);
}

void GUIOverlay::SetPlayerHatching(int i){
	wichMustHatch=i;
}

void GUIOverlay::SetHeatMaxMin(float max,float min){

	temp_bar->SetMaxMin(max,min);

}

void GUIOverlay::SetHeat(float value){
	temp_bar->SetValue(value);
}
